# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy
from scrapy.loader.processors import TakeFirst
from urllib import parse

free_imooc_domain = 'https://www.imooc.com/'


def get_free_course_url(value):
    # print(free_imooc_domain, value)
    return parse.urljoin(free_imooc_domain, value[0])


def get_img_url(value):
    return parse.urljoin(free_imooc_domain, value[0])


def get_free_course_num(value):
    # print(free_imooc_domain, value)
    return value[0].split('/')[-1]


class ImoocItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    pass


class ImoocFreeCourseListItem(scrapy.Item):
    course_url = scrapy.Field(output_processor=get_free_course_url)
    course_num = scrapy.Field(output_processor=get_free_course_num)
    # course_num = scrapy.Field(output_processor=TakeFirst())
    course_img_url = scrapy.Field(output_processor=get_img_url)
    # img_src = scrapy.Field(output_processor=get_img_url)
    course_name = scrapy.Field(output_processor=TakeFirst())
    course_level = scrapy.Field(output_processor=TakeFirst())
    course_student_num = scrapy.Field(output_processor=TakeFirst())
    course_short_desc = scrapy.Field(output_processor=TakeFirst())
    course_price = scrapy.Field(output_processor=TakeFirst())
    course_cost_price = scrapy.Field(output_processor=TakeFirst())
    course_label = scrapy.Field()
    created_at = scrapy.Field(output_processor=TakeFirst())
